package com.shixun.milktea.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shixun.milktea.entity.Mt;
import com.shixun.milktea.mapper.MtMapper;
import com.shixun.milktea.service.MtService;
import com.shixun.milktea.vo.PageVo;
import com.shixun.milktea.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zrs
 * @since 2022-06-07
 */
@RestController
@RequestMapping("/mt")
@Api(tags = "奶茶商品相关接口")
public class MtController {
    @Autowired
    MtMapper mtMapper;
    @Autowired
    MtService mtService;
    @GetMapping("/findAllMilktea")
    @ApiOperation(value = "查询所有奶茶")
    public ResultVO queryAllMilktea() throws Exception {
        QueryWrapper<Mt> qw=new QueryWrapper<>();
        List<Mt> mtList = mtMapper.selectList(qw);

        return new ResultVO(mtList);
    }
    @PostMapping("/addMilktea")
    @ApiOperation(value = "添加奶茶信息")
    public ResultVO addMilktea(@RequestBody Mt mt) throws Exception {

        int insert = mtMapper.insert(mt);

        return new ResultVO(insert);
    }
    @DeleteMapping("/deleteMilkteaById")
    @ApiOperation(value = "根据id删除奶茶信息")
    public ResultVO deleteMilktea(@RequestParam("mtId") int mtId) throws Exception {
        int i = mtMapper.deleteById(mtId);
        return new ResultVO(i);
    }
    @GetMapping("/queryMilkteaById")
    @ApiOperation(value = "根据id查询奶茶信息")
    public ResultVO queryMilkteaById(@RequestParam("mtId") int mtId) throws Exception {
        Mt mt = mtMapper.selectById(mtId);
        return new ResultVO(mt);
    }
    @PutMapping("/updateMilktea")
    @ApiOperation(value = "修改奶茶信息")
    public ResultVO updateMilktea(@RequestBody Mt mt) throws Exception {

        int i = mtMapper.updateById(mt);

        return new ResultVO(i);
    }
    @GetMapping("/findMilkteaByPrice")
    @ApiOperation(value = "根据价格查询奶茶信息")
    public ResultVO findMilkteaByPrice(@RequestParam("mtprice") double mtPrice) throws Exception {

        QueryWrapper<Mt> wrapper = new QueryWrapper<>();
        wrapper.eq("mt_price",mtPrice);
        List<Mt> mtList = mtMapper.selectList(wrapper);


        return new ResultVO(mtList);
    }
    @GetMapping("/findMilkteaByNum")
    @ApiOperation(value = "根据库存量查询奶茶信息")
    public ResultVO findMilkteaByNum(@RequestParam("mtNum") int mtNum) throws Exception {

        QueryWrapper<Mt> wrapper = new QueryWrapper<>();
        wrapper.eq("mt_num",mtNum);
        List<Mt> mtList = mtMapper.selectList(wrapper);

        return new ResultVO(mtList);
    }
    @GetMapping("/findMilkteaBySortId")
    @ApiOperation(value = "根据分类id查询奶茶信息")
    public ResultVO findMilkteaBySortId(@RequestParam("sortId") int sortId) throws Exception {

        QueryWrapper<Mt> wrapper = new QueryWrapper<>();
        wrapper.eq("sort_id",sortId);
        List<Mt> mtList = mtMapper.selectList(wrapper);

        return new ResultVO(mtList);
    }
    @GetMapping("/moHuQueryLike")
    @ApiOperation(value = "搜索框模糊分页查询奶茶信息")
    public ResultVO MohuQueryLike(PageVo pageVo,String mtName
    ) throws Exception {

        Page<Mt> mtPage = mtService.MtQueryList(pageVo,mtName);

        return new ResultVO(mtPage);
    }
    @GetMapping("/QueryPagelist")
    @ApiOperation(value = "分页查询奶茶信息")

    public ResultVO QueryPagelist(PageVo pageVo) throws Exception {

            Page<Mt> jobPage = mtService.selectPage(pageVo);

            return new ResultVO(jobPage);
    }
    @GetMapping("/findMilkteaByShelves")
    @ApiOperation(value = "查询上架的奶茶信息")
    public ResultVO findMilkteaByShelves(@RequestParam("mtShelves") int mtShelves) throws Exception {

        QueryWrapper<Mt> wrapper = new QueryWrapper<>();
        wrapper.eq("mt_shelves",mtShelves);
        List<Mt> mtList = mtMapper.selectList(wrapper);

        return new ResultVO(mtList);
    }
    @GetMapping("/findMilkteaByNew")
    @ApiOperation(value = "查询新品的奶茶信息")
    public ResultVO findMilkteaByNew(@RequestParam("mtNew") int mtNew) throws Exception {
        QueryWrapper<Mt> wrapper = new QueryWrapper<>();
        wrapper.eq("mt_new",mtNew);
        List<Mt> mtList = mtMapper.selectList(wrapper);


        return new ResultVO(mtList);
    }
    @PutMapping("/updateMtStatusUp")
    @ApiOperation(value = "奶茶上架")
    public ResultVO updateMtStatusUp(@RequestParam("mtId") int mtId) throws Exception {
        int i = mtService.updateMtStatusUp(mtId);
        return new ResultVO(i);
    }

    @PutMapping("/updateMtStatusDown")
    @ApiOperation(value = "奶茶下架")
    public ResultVO updateMtStatusDown(@RequestParam("mtId") int mtId) throws Exception {
        int i = mtService.updateMtStatusDown(mtId);
        return new ResultVO(i);
    }
    @PutMapping("/updateMtNewUp")
    @ApiOperation(value = "奶茶上新")
    public ResultVO updateMtNewUp(@RequestParam("mtId") int mtId) throws Exception {
        int i = mtService.updateMtNewUp(mtId);
        return new ResultVO(i);
    }

    @PutMapping("/updateMtNewDown")
    @ApiOperation(value = "奶茶下新")
    public ResultVO updateMtNewDown(@RequestParam("mtId") int mtId) throws Exception {
        int i = mtService.updateMtNewDown(mtId);
        return new ResultVO(i);
    }
}
